package cn.ww.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

//@EnableWebSecurity(debug = true) // 启动SpringSecurity过滤器链
public class SecurityConfJdbc extends WebSecurityConfigurerAdapter {

 
    
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
        .antMatchers("/product/add").hasRole("ADMIN")
        .antMatchers("/product/update").hasRole("ADMIN")
        .antMatchers("/product/delete").hasRole("ADMIN")
        .antMatchers("/product/list").hasRole("USER")
        .anyRequest().authenticated()
        .and().formLogin().loginPage("/userLogin").loginProcessingUrl("/login").permitAll()
        .and().csrf().disable();
    
        

    }
    
    //为学习测试方便,用明文储存密码
    @Bean
    public PasswordEncoder passwordEncoder() {
        return NoOpPasswordEncoder.getInstance();
    }

}
